﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Core.Graphics;

namespace WorldEditor.Tiles
{
    public partial class AutoTilePallet : UserControl
    {
        public event EventHandler SelectedAutoTileInfoChanged;

        public AutoTilePallet()
        {
            InitializeComponent();

            LoadAutoTilePallet();
        }

        public void LoadAutoTilePallet()
        {
            flpAutoTileInfoTiles.Controls.Clear();

            foreach (AutoTileInfo ati in AutoTileInfoCollection.GlobalAutoTileSets)
            {
                AutoTilePalletTile atp = new AutoTilePalletTile();
                atp.AutoTileInfo = ati;
                atp.LoadAutoTileInfo();

                atp.AutoTileInfoSelected += new EventHandler(atp_AutoTileInfoSelected);

                flpAutoTileInfoTiles.Controls.Add(atp);
            }
        }

        void atp_AutoTileInfoSelected(object sender, EventArgs e)
        {
            //Remove borders on all items
            foreach (AutoTilePalletTile atpt in flpAutoTileInfoTiles.Controls)
            {
                atpt.BorderStyle = BorderStyle.None;
            }

            AutoTilePalletTile atptSelected = (AutoTilePalletTile)sender;
            //Set border on selected so we can see which one is selected
            atptSelected.BorderStyle = BorderStyle.FixedSingle;

            if (SelectedAutoTileInfoChanged != null)
                SelectedAutoTileInfoChanged.Invoke(atptSelected.AutoTileInfo, EventArgs.Empty);
        }
    }
}
